#include "../../framework/inc/xApp.h"
#include "../inc/xTimer.h"
namespace NTools
{

VOID  CALLBACK   adpTimerProc( HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)
{
	xTimer::myAdapData data = xGlobal<xTimer::myAdapData>::get();
	data.proc(data.pUser);
	return;
}

TBool xTimer::CreateTimer( TInt timerID,TimerProc proc,TInt span ,TVoid* pUser)
{
	if(mCreated)
		return vTrue;
	HWND hwnd = xGlobal<xIApp*>::get()->getWindow()->getHWnd();
	myAdapData data;
	data.proc = proc;
	data.pUser = pUser;

	xGlobal<xTimer::myAdapData>::set(data);

	if(hwnd == vNull)
		return vFalse;
	TInt i = ::SetTimer(vNull,1,span/1000,adpTimerProc);
	DWORD R = ::GetLastError();
	mTimerID = timerID;
	mCreated = vTrue; 
	return vTrue;
}

TVoid xTimer::DeleteTimer( TInt timerID )
{
	if(mCreated == vFalse)
		return;
	HWND hwnd = xGlobal<xIApp*>::get()->getDevice()->getDeviceWindow();
	if(hwnd == vNull)
		return ;;
	KillTimer(vNull ,timerID);
	mCreated = vFalse;
	return;
}



xTimer::~xTimer()
{
	DeleteTimer(mTimerID);
}
}
